// #ifndef VUE3
import Vue from 'vue'
import App from './App'
import common from './common/common.scss'



Vue.config.productionTip = false

App.mpType = 'app'

const app = new Vue({
	...App
})
app.$mount()
// #endif

// #ifdef VUE3
import {
	createSSRApp
} from 'vue'
import App from './App.vue'

"usingComponents": {
	"van-button": "./vant-weapp/dist/button"
},

export function createApp() {
	const app = createSSRApp(App)
	return {
		app
	}
}
// #endif

const saveImage = function(e) {
	uni.downloadFile({
		url: e,
		success: function(res) {
			console.log(res);
			//图片保存到本地
			uni.saveImageToPhotosAlbum({
				filePath: res.tempFilePath,
				success: function(data) {
					uni.showToast({
						title: '保存成功',
						icon: 'success',
						duration: 2000
					})
				},
				fail: function(err) {
					console.log(err);
					if (err.errMsg === "saveImageToPhotosAlbum:fail auth deny") {
						console.log("当初用户拒绝，再次发起授权")
						uni.openSetting({
							success(settingdata) {
								console.log(settingdata)
								if (settingdata.authSetting[
										'scope.writePhotosAlbum']) {
									console.log('获取权限成功，给出再次点击图片保存到相册的提示。')
								} else {
									console.log('获取权限失败，给出不给权限就无法正常使用的提示')
								}
							}
						})
					}
				},
				complete(res) {
					console.log(res);
				}
			})
		}
	})
}
const saveFile = function(e) {
	let FileSystemManager = uni.getFileSystemManager();
	uni.downloadFile({
		url: e,
		success: function(res) {
			console.log(res);
			//图片保存到本地
			uni.openDocument({
				filePath: res.tempFilePath,
				showMenu: true,
				success: function(data) {
					FileSystemManager.open({
						filePath: data.savedFilePath,
						success: function(data) {

						},
						fail: function(err) {

						},
						complete(res) {

						}
					})
				},
				fail: function(err) {

				},
				complete(res) {
					console.log(res);
				}
			})
		}
	})
}


Vue.prototype.$uniApi = {
	saveImage,
	saveFile
};
